<?php

namespace App\Models;

use PDO;

/**
 * Example user model
 *
 * PHP version 7.0
 */
class User extends \Core\Model
{
    public $tableName = 'users';

    /**
     * Get all the users as an associative array
     *
     * @return array
     */
    public  function getAll() {
        $db = static::getDB();
        $stmt = $db->query('SELECT * FROM users');
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    public   function Insert($user){
        $db = static::getDB();
        $stmt = $db->query(`insert into users('user_name','user_pwd','create_date','update_date','display_name'
        ,'email_address','tel','avatar') values (` + $user["user_name"] + `,` +
            $user["user_pwd"] + `,` +
            $user["create_date"] + `,` +
            $user["update_date"] + `,` +
            $user["display_name"] + `,` +
            $user["email_address"] + `,` +
            $user["tel"] + `,` +
            $user["avatar"] + `,` +
            + `)` + `ON DUPLICATE KEY UPDATE users.user_name = ` + $user["user_pwd"]  + `,` +
            `users.user_pwd = `  +$user["user_pwd"] + `,` +
            `users.create_date = `  +$user["create_date"] + `,` +
            `users.update_date = `  +$user["update_date"] + `,` +
            `users.display_name = `  +$user["display_name"] + `,` +
            `users.email_address = `  +$user["email_address"] + `,` +
            `users.tel = `  +$user["tel"] + `,` +
            `users.avatar = `  +$user["avatar"] + `,`
        );
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }

}
